package cn.stylefeng.guns.modular.transport.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.transport.entity.TransportCarrierFreight;
import cn.stylefeng.guns.modular.transport.mapper.TransportCarrierFreightMapper;
import cn.stylefeng.guns.modular.transport.model.params.TransportCarrierFreightParam;
import cn.stylefeng.guns.modular.transport.model.result.TransportCarrierFreightResult;
import  cn.stylefeng.guns.modular.transport.service.TransportCarrierFreightService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 承运商运费信息表 服务实现类
 * </p>
 *
 * @author like
 * @since 2024-10-15
 */
@Service
public class TransportCarrierFreightServiceImpl extends ServiceImpl<TransportCarrierFreightMapper, TransportCarrierFreight> implements TransportCarrierFreightService {

    @Override
    public void add(TransportCarrierFreightParam param){
        TransportCarrierFreight entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TransportCarrierFreightParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TransportCarrierFreightParam param){
        TransportCarrierFreight oldEntity = getOldEntity(param);
        TransportCarrierFreight newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TransportCarrierFreightResult findBySpec(TransportCarrierFreightParam param){
        return null;
    }

    @Override
    public List<TransportCarrierFreightResult> findListBySpec(TransportCarrierFreightParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TransportCarrierFreightParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findPageBySpec2(TransportCarrierFreightParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList2(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findPageBySpec3(TransportCarrierFreightParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList3(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findPageBySpec4(TransportCarrierFreightParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList4(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TransportCarrierFreightParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TransportCarrierFreight getOldEntity(TransportCarrierFreightParam param) {
        return this.getById(getKey(param));
    }

    private TransportCarrierFreight getEntity(TransportCarrierFreightParam param) {
        TransportCarrierFreight entity = new TransportCarrierFreight();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
